import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      meta: { title: '首页' },
      component: () => import('@/views/Home.vue'),
    },
    {
      path: '/addTeacher',
      name: 'addTeacher',
      meta: { title: '新增老师' },
      component: () => import('@/views/AddTeacher.vue'),
    },
    {
      path: '/updateTeacher/:id',
      name: 'updateTeacher',
      meta: { title: '修改老师' },
      component: () => import('@/views/UpdateTeacher.vue'),
    },
  ],
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
